#-*- encoding: utf-8 -*-
#---------------------------------------------------------------------------------
# SConscript
# Copyright (c) 2024, Shanghai Real-Thread Electronic Technology Co., Ltd.
#---------------------------------------------------------------------------------
import os
from building import *
Import('RTT_ROOT')
Import('rtconfig')

#---------------------------------------------------------------------------------
# Package configuration
#---------------------------------------------------------------------------------
PKGNAME = 'hpm_lib'
DEPENDS = []

#---------------------------------------------------------------------------------
# Compile the configuration
#---------------------------------------------------------------------------------
SOURCES          = []

CPPPATH          = [os.path.join(GetCurrentDir(), 'inc')]

SOURCES          += Glob('src/hpm_pmp_drv.c')
SOURCES          += Glob('src/hpm_pcfg_drv.c')

if rtconfig.SOC_FAMILY == "HPM6700":
    SOURCES += ['src/hpm_pllctl_drv.c']
else:
    SOURCES += ['src/hpm_pllctlv2_drv.c']

if rtconfig.SOC_FAMILY == "HPM6700" or rtconfig.SOC_FAMILY == "HPM6300" or rtconfig.SOC_FAMILY == "HPM6200":
    SOURCES += ['src/hpm_dma_drv.c']
else:
    SOURCES += ['src/hpm_dmav2_drv.c']
    CPPDEFINES = ['HPMSOC_HAS_HPMSDK_DMAV2']

if GetDepend(['BSP_USING_GPIO']):
    SOURCES += ['src/hpm_gpio_drv.c']

if GetDepend(['BSP_USING_UART']):
    SOURCES += ['src/hpm_uart_drv.c']

if GetDepend(['BSP_USING_I2C']):
    SOURCES += ['src/hpm_i2c_drv.c']

if GetDepend(['BSP_USING_SPI']):
    SOURCES += ['src/hpm_spi_drv.c']

if GetDepend(['BSP_USING_RTC']):
    SOURCES += ['src/hpm_rtc_drv.c']

if GetDepend(['BSP_USING_WDG']):
    SOURCES += ['src/hpm_wdg_drv.c']

if GetDepend(['BSP_USING_EWDG']):
    SOURCES += ['src/hpm_ewdg_drv.c']

if GetDepend(['BSP_USING_ADC']):
    if GetDepend(['BSP_USING_ADC12']):
        SOURCES += ['src/hpm_adc12_drv.c']
    if GetDepend(['BSP_USING_ADC16']):
        SOURCES += ['src/hpm_adc16_drv.c']

if GetDepend(['BSP_USING_CAN']):
    SOURCES += ['src/hpm_can_drv.c']

if GetDepend(['BSP_USING_MCAN']):
    SOURCES += ['src/hpm_mcan_drv.c']

if GetDepend(['BSP_USING_ETH']):
    SOURCES += ['src/hpm_enet_drv.c']

if GetDepend(['BSP_USING_DMA']):
    SOURCES += ['src/hpm_dma_drv.c']

if GetDepend(['BSP_USING_SDXC']):
    SOURCES += ['src/hpm_sdxc_drv.c']

if GetDepend(['BSP_USING_LCD']):
    SOURCES += ['src/hpm_lcdc_drv.c']

if GetDepend(['BSP_USING_GPTMR']) or GetDepend('HPM_USING_VECTOR_PREEMPTED_MODE'):
    SOURCES += ['src/hpm_gptmr_drv.c']

if GetDepend(['BSP_USING_FEMC']):
    SOURCES += ['src/hpm_femc_drv.c']

if GetDepend(['BSP_USING_PWM']):
    SOURCES += ['src/hpm_pwm_drv.c']

if GetDepend(['BSP_USING_PWMV2']):
    SOURCES += ['src/hpm_pwmv2_drv.c']

if GetDepend(['BSP_USING_USB']):
    SOURCES += ['src/hpm_usb_drv.c']

if GetDepend(['BSP_USING_I2S']):
    SOURCES += ['src/hpm_i2s_drv.c']

if GetDepend(['BSP_USING_PDM']):
    SOURCES += ['src/hpm_pdm_drv.c']
    SOURCES += ['src/hpm_i2s_drv.c']

if GetDepend(['BSP_USING_DAO']):
    SOURCES += ['src/hpm_dao_drv.c']
    SOURCES += ['src/hpm_i2s_drv.c']

if GetDepend(['BSP_USING_PDMA']):
    SOURCES += ['src/hpm_pdma_drv.c']

if GetDepend(['BSP_USING_JPEG']):
    SOURCES += ['src/hpm_jpeg_drv.c']

if GetDepend(['BSP_USING_CAM']):
    SOURCES += ['src/hpm_cam_drv.c']

if GetDepend(['BSP_USING_PIXELMUX']):
    SOURCES += ['src/hpm_pixelmux_drv.c']

if GetDepend(['BSP_USING_MIPI_CSI']):
    SOURCES += ['src/hpm_mipi_csi_drv.c']
    SOURCES += ['src/hpm_mipi_csi_phy_drv.c']

if GetDepend(['BSP_USING_MIPI_DSI']):
    SOURCES += ['src/hpm_mipi_dsi_drv.c']
    SOURCES += ['src/hpm_mipi_dsi_phy_drv.c']

if GetDepend(['BSP_USING_LVB']):
    SOURCES += ['src/hpm_lvb_drv.c']

if GetDepend(['BSP_USING_LCB']):
    SOURCES += ['src/hpm_lcb_drv.c']
#---------------------------------------------------------------------------------
# Feature clip configuration, optional
#---------------------------------------------------------------------------------

#---------------------------------------------------------------------------------
# Compiler platform configuration, optional
#---------------------------------------------------------------------------------

#---------------------------------------------------------------------------------
# System variables
#---------------------------------------------------------------------------------
objs   = []
root   = GetCurrentDir()

#---------------------------------------------------------------------------------
# Sub target
#---------------------------------------------------------------------------------
list = os.listdir(root)
if GetDepend(DEPENDS):
    for d in list:
        path = os.path.join(root, d)
        if os.path.isfile(os.path.join(path, 'SConscript')):
            objs = objs + SConscript(os.path.join(d, 'SConscript'))

#---------------------------------------------------------------------------------
# Main target
#---------------------------------------------------------------------------------
objs += DefineGroup(name = PKGNAME, src = SOURCES, depend = DEPENDS, CPPPATH = CPPPATH)

Return("objs")
#---------------------------------------------------------------------------------
# End
#---------------------------------------------------------------------------------
